<template>
    <div class="container-filled">
        <el-container>
            <el-main style="padding:0;">
                <!-- 展示表格 -->
                <el-table :data="commentRows.slice((pageNum - 1) * pageSize, pageNum * pageSize)">
                    <el-table-column v-for="item in elTableColumns" :prop="item.prop" :label="item.label"
                        :width="item.width" />
                    <el-table-column label="操作" fixed="right" width="250">
                        <template v-slot="scope" #default>
                            <el-button type="primary" size="small" @click="checkComment(scope.row._id)" link>审核
                            </el-button>
                        </template>
                    </el-table-column>
                </el-table>
            </el-main>
            <!-- 分页模块 -->
            <el-footer>
                <el-pagination background layout="prev, pager, next" @size-change="handleSizeChange"
                    @current-change="handleCurrentChange" :total="total" :current-page="pageNum"
                    :default-page-size="pageSize" style="width: 400px;margin:1em auto 0 auto;" />
            </el-footer>
        </el-container>
    </div>
</template>
<script>// @ts-nocheck
import { ElMessage } from "element-plus"
import api from "../../api/api"
export default {
    data() {
        return {
            total: 0,
            pageNum: 1,
            pageSize: 10,
            commentRows: [],
            elTableColumns: [
                {
                    prop: "movie_id",
                    label: "电影id",
                    width: ""
                }, {
                    prop: "username",
                    label: "用户名",
                    width: ""
                }, {
                    prop: "context",
                    label: "评论内容",
                    width: ""
                }
            ],
            nowUserRow: {},
        }
    },
    created() {
        api.get("/admin/movie/comment/false").then((res) => {
            this.total = res.data.total
            this.commentRows = res.data.rows
        })
    },
    methods: {
        // 分页相关
        handleSizeChange(val) {
            this.pageSize = val
            console.log(`每页 ${val} 条`)
        },
        handleCurrentChange(val) {
            this.pageNum = val
        },
        // 点击删除评论
        checkComment(id) {
            api.put("/admin/movie/comment/" + id).then((res) => {
                // 重新请求刷新列表
                api.get("/admin/movie/comment/false").then((res) => {
                    this.total = res.data.total
                    this.commentRows = res.data.rows
                })
                res.data.status === 0 ? ElMessage.success(res.data.message) : ElMessage.error("操作失败!")
            })
        }
    }
}
</script>
<style lang="sass" scoped>

</style>